package liuch.basic;

/**
 * 〈一句话功能简述〉测试runable的可用性，不加锁<br>
 * 〈功能详细描述〉
 *
 * @author 17101651 on 2018/7/12.
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class RunableAndThreadTest implements Runnable {
    private int a = 10;

    @Override
    public void run() {
        for (int i = 0; i < 100 && a > 0; i++) {
            a--;
            System.out.println(Thread.currentThread().getName() + "|" + a);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        RunableAndThreadTest runableTest = new RunableAndThreadTest();
        new Thread(runableTest).start();
        new Thread(runableTest).start();
        new Thread(runableTest).start();
//        new ThreadAndRunableTest().start();
//        new ThreadAndRunableTest().start();
//        new ThreadAndRunableTest().start();
    }
    class ThreadAndRunableTest extends Thread {
        private int a = 10;

        @Override
        public void run() {
            for (int i = 0; i < 100 && a > 0; i++) {
                a--;
                System.out.println(Thread.currentThread().getName() + "|" + a);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

